﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZkSurvey.Common.SurveyMgr;
using ZkSurvey.BLL.SurveyMgr;
using ZkSurvey.Web.Helper;
using ZkSurvey.Web.Helper.Extensions;
namespace ZkSurvey.Web.VP.SurveyResult
{
    public partial class List : System.Web.UI.UserControl
    {
        ExternalUserBl extUserBl = new ExternalUserBl();
        SurveyBl surveyBl = new SurveyBl();


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //加载所有运行中和结束的问卷调查
                List<Survey> surveies = surveyBl.GetSurveyList().FindAll(s => s.Status != SurveyStatus.NotStarted);
                ddlSurvey.DataSource = surveies;
                ddlSurvey.DataTextField = "Title";
                ddlSurvey.DataValueField = "Id";
                ddlSurvey.DataBind();
                if (ddlSurvey.Items.Count > 0)
                {
                    ddlSurvey_SelectedIndexChanged(null, null);
                    HlViewSummary.Visible = true;
                }
            }
        }

        protected void GvList_RowCommand(object sender, GridViewCommandEventArgs e)
        {

        }

        protected void GvList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

        protected void GvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            GvList.ShowRowNumber(e);
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Participation partic = (Participation)e.Row.DataItem;
                ((HyperLink)e.Row.FindControl("HlAudit")).NavigateUrl = UrlHelper.GenerateUrl("SvRstAudit", "Id", partic.Id.ToString());
            }

        }

        protected void ddlSurvey_SelectedIndexChanged(object sender, EventArgs e)
        {
            int svId = Convert.ToInt32(ddlSurvey.SelectedValue);

            List<Participation> partics = extUserBl.GetParticipationList(svId);
            GvList.DataSource = partics;
            GvList.DataBind();

            HlViewSummary.NavigateUrl = UrlHelper.GenerateUrl("SvRstSummary", "Id", svId.ToString());
        }
    }
}